class MinStack2 {
  stack: number[];
  min_stack: number[];
  
  constructor() {
    this.stack = [];
    this.min_stack = [];
  }
  
  push(val: number) {
    this.stack.push(val);
    if (this.min_stack.length === 0 ||  val <= this.min_stack[this.min_stack.length  - 1]) {
      this.min_stack.push(val);
    }
  }
  
  pop() {
    if (this.stack.length === 0) return;
    if (this.stack.pop() === this.min_stack[this.min_stack.length  - 1]) {
      this.min_stack.pop();
    }
  }
  
  top(): number {
    return this.stack[this.stack.length - 1];
  }
  
  getMin(): number {
    return this.min_stack[this.min_stack.length - 1];
  }
}


const test2 = new MinStack2();
test2.push(-2);
test2.push(0);
test2.push(-3);
console.log(test2.getMin());
test2.pop();
console.log(test2.top());
console.log(test2.getMin());
